{extend name="./theme/backend/base.html"}
{block name="content"}
<style type="text/css">
.replace_column{margin: 10px 0;}
.alltxt{line-height: 18px;padding: 3px 3px 2px 3px;vertical-align: middle;border-width: 1px;border-style: solid;}
.fields{display: none;padding: 6px;border: 1px #33485d dashed;margin: 10px 0;}
.table_label{margin-bottom: 6px;color: #0087ff;}
.fields span{display: inline-block; margin: 0 10px 10px 0;background-color:#e8e8e8;padding: 0 4px;border-radius: 5px;color: #868686; cursor: pointer;}
</style>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li class="active"><a href="{:url('cms/posts/replace')}">内容批量替换</a></li>
	</ul>
	<form method="post" class="form-horizontal js-ajax-form" action="">
	<fieldset>
        <div class="tabbable">
            <div class="tab-content">
            	<div class="tab-pane active" id="A">
					<fieldset>
					<div class=""> 
					<table class="table table-bordered"> 
					<tbody>
					<tr> 
						<th width="80">选择数据表与字段</th> 
						<td>
							<select id="exptable" name="exptable" size="10" style="width:60%">
								{volist name="listTables" id="vo"}
								<option value="{$vo}">{$vo}</option>
								{/volist}
							</select>
							<div class="fields">
								
							</div>
							<div class="replace_column">要替换的字段：<input type="text" name="column" class="column" class="alltxt" style="border-width: 1px;" /></div>
						</td> 
					</tr>
					<tr> 
						<th width="80">内容替换方式：</th> 
						<td> 
							<label><input type="radio" name="replace_way" value="1" checked />普通替换</label>
							<label><input type="radio" name="replace_way" value="2"/>正则替换</label>
							<span class="form-required"> </span> 
						</td> 
					</tr>
					<tr> 
						<th width="80">被替换内容：</th> 
						<td> 
							<textarea name="rpstring" id="rpstring" class="alltxt" style="width:60%;height:50px"></textarea>
							<span class="form-required"> </span> 
						</td> 
					</tr>
					<tr> 
						<th width="80">替换为：</th> 
						<td> 
							<textarea name="tostring" id="tostring" class="alltxt" style="width:60%;height:50px"></textarea>
							<span class="form-required"></span>
						</td> 
					</tr>  
					<tr> 
						<th>替换条件：</th> 
						<td>
							<input name="condition" type="text" id="condition" style="width:45%;border-width: 1px;" class="alltxt">
							<span class="form-required red"> 不写替换所有</span>
						</td> 
					</tr> 
					
					</tbody>
					</table> 
					</div>
					</fieldset>
				</div>
			</div>
		</div>
		<div class="form-actions">
			<button class="btn btn-primary js-ajax-button" type="button">确定操作</button>
			<a class="btn" href="javascript:history.back(-1);">返回</a>
		</div>
	</fieldset>
</form>
</div>
<script src="{$admin_assets_path}/js/common.js"></script>
<script type="text/javascript">
$(function(){
	$("#exptable").click(function(){
		let field=$(this).val();
		new AjaxRequest({
			url:"{:url('cms/Posts/getFields')}",
			param:{"field":field},
			callBack:function(data){
				$(".fields").empty().hide();
				console.log(data);
				let filed_str="<div class='table_label'>表（"+field+"）中包含的字段：</div>";
				for(let i in data){
					console.log(data[i]);
					filed_str+="<span onclick='chooseField(\""+data[i]+"\")'>"+data[i]+"</span>";
				}
				$(".fields").append(filed_str).show();
			}
		});
	});
});
function chooseField(field){
	$(".column").val(field);
}
</script>
{/block}